﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;

namespace DataAccess.Classes
{
   public class NguoiDung1
    {
        public string IDNguoiDung { get; set; }
        public string MatKhau { get; set; }
        public string MaNhom { get; set; }
        public string TenNhom { get; set; }
        public string TenNguoiDung { get; set; }
        public string SoDienThoai { get; set; }
        public DateTime NgaySinh { get; set; }
        public bool GioiTinh { get; set; }
        public string DiaChi { get; set; }
        public string Hinh { get; set; }

        public NguoiDung1() { }



        // Lay thong tin nguoi dung

        public static NguoiDung1 LayThongTinNguoiDung(string nguoiDung)
        {
            try
            {
                return CBO.FillObject<NguoiDung1>(DataProvider.Instance.ExecuteReader("LayThongTinNguoiDung", nguoiDung));
            }
            catch
            {
                return null;
            }
        }
        public static List<NguoiDung1> LayTatCa()
        {
            try
            {
                return CBO.FillCollection<NguoiDung1>(DataProvider.Instance.ExecuteReader("NguoiDung_LayTatCa"));
            }
            catch (Exception)
            {

                return null;
            }
        }
        public static List<NguoiDung1> LayTatCaAdmin()
        {
            try
            {
                return CBO.FillCollection<NguoiDung1>(DataProvider.Instance.ExecuteReader("NguoiDung_LayTatCaAdmin"));
            }
            catch (Exception)
            {

                return null;
            }
        }
        public static List<NguoiDung1> TimKiem(string paramater)
        {
            try
            {
                return CBO.FillCollection<NguoiDung1>(DataProvider.Instance.ExecuteReader("NhomNguoiDung_TimKiemNguoiDung", paramater));
            }
            catch (Exception)
            {

                return null;
            }
        }
        public static bool DoiMatKhau(string tenDangNhap, string matKhau)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("NguoiDung_DoiMatKhau", tenDangNhap, matKhau);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }

        }
        public static bool CapNhatAvatar(string tenDangNhap, string hinh)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("NguoiDung_CapNhatAvatar", tenDangNhap, hinh);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }

        }
        public static bool CapNhat(string tenDangNhap, NguoiDung1 nguoidung)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("NguoiDung_CapNhat", tenDangNhap, nguoidung.TenNguoiDung, nguoidung.SoDienThoai, nguoidung.NgaySinh, nguoidung.GioiTinh, nguoidung.DiaChi, nguoidung.Hinh);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }

        }
        public static bool CapNhatThongTin(string tenDangNhap, NguoiDung1 nguoidung)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("NguoiDung_CapNhatThongTin", tenDangNhap, nguoidung.TenNguoiDung, nguoidung.SoDienThoai, nguoidung.NgaySinh, nguoidung.GioiTinh, nguoidung.DiaChi);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }

        }
        public static NguoiDung1 LayTheoTenDangNhap(string tenDangNhap)
        {
            try
            {
                return CBO.FillObject<NguoiDung1>(DataProvider.Instance.ExecuteReader("NguoiDung_LayTheoTenDangNhap", tenDangNhap));
            }
            catch (Exception)
            {
                return null;
            }
        }
        public static bool Them(NguoiDung1 nguoiDung)
        {

            
        
                object rs = DataProvider.Instance.ExecuteNonQuery("NguoiDung_Them",
                         nguoiDung.IDNguoiDung, nguoiDung.MaNhom, nguoiDung.TenNguoiDung, nguoiDung.MatKhau, nguoiDung.NgaySinh);
                return Convert.ToInt32(rs) > 0;
     
          
        }

        public static bool Xoa(string tenDangNhap)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("NguoiDung_Xoa", tenDangNhap);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }
        }
        // dem so luong nguoi dang dung
        public static int DemNguoiDung()
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteScalar("NguoiDung_Dem");
                return Convert.ToInt32(rs);
            }
            catch
            {
                return Convert.ToInt32(0);
            }

        }
    }
}
